<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <style>
  .aligns{text-align:center}
  .right{float:right}
  </style>
  <title>e网批发管理后台</title>
  <link type="text/css" rel="stylesheet" href="time/css/lanrenzhijia.css" />
  <link rel="stylesheet" type="text/css" href="time/css/jquery-ui.css" />
  <script type="text/javascript" src="js/jquery.min.js"></script>
  <script src="time/js/jquery-ui-1.10.4.custom.min.js"></script>
  <script src="time/js/jquery.ui.datepicker-zh-CN.js"></script>
  <script src="time/js/jquery-ui-timepicker-addon.js"></script>
  <script src="time/js/jquery-ui-timepicker-zh-CN.js"></script>
  <script language="javascript" type="text/javascript" src="datepicker/WdatePicker.js"></script>
  <?php include("common/conn.php");

function intpos($s){
  $a=floor($s*100)/100;
  return $a;
}

$perNumber=20; //每页显示的记录数
$page=$_GET['page']; //获得当前的页面值

if (!isset($page)) {
  $page=1;
} //如果没有值,则赋值1
$startCount=($page-1)*$perNumber; //分页开始,根据此方法计算出开始的



  if($_GET['del']=="ok"){
    $area = array(); 
    $area= $_POST['checkbox'];

    foreach ($area as $k=>$v)
    {
      $srat1=mysql_query("DELETE FROM shop where shopid='".$v."'");
    }

  }

  if ($_GET['cancel']='ok') {
    $srat1=mysql_query("DELETE FROM ad where id='".$_GET['id']."'");
  }

  // 一键审核通过
  if ($_REQUEST['act'] == 'passall') {
      $shopids = $_REQUEST['shopids'];
      $query = mysql_query("UPDATE shop set `check` = 1 where shopid in (".$shopids.")");
      echo "<script>alert('修改成功');window.location.href='shequ.php'</script>";
  }
  // 一键审核通过 end

// 是否通过审核
if ($_REQUEST[check]!='') {
  mysql_query("UPDATE shop set `check`=".$_REQUEST[check]." where shopid=".$_REQUEST[shopid]);
  echo "<script>window.location.href='shequ.php'</script>";
}
// 是否通过审核 end

// 获取时间
if (isset($_REQUEST['date']) && isset($_REQUEST['dateL'])) {
  $date=$_REQUEST['date'];
  $dateL=$_REQUEST['dateL'];
  $date=date("Y-m-d",strtotime($date));
  $lateL=date("Y-m-d",strtotime($dateL));
  $between=" and fu_kuan_datetime>'".$date."' and fu_kuan_datetime<'".$lateL."'";
}else{
  $date=date("Y-m-d",(time() - 3600*24*15));
  $dateL=date("Y-m-d",(time() + 3600*12));
  $between=" and fu_kuan_datetime>'".$date."' and fu_kuan_datetime<'".$dateL."'";
}


$_REQUEST['s'] = !empty($_REQUEST['s'])?$_REQUEST['s']:null;
$_REQUEST['cid'] = !empty($_REQUEST['categroys'])?$_REQUEST['categroys']:null;
$_REQUEST['sid'] = !empty($_REQUEST['shops'])?$_REQUEST['shops']:null;

if($_REQUEST['cid']){
  $cid = ($_REQUEST['cid']=='0') ? '' : " and leimu=$_REQUEST[cid] ";
}

if($_REQUEST['sid']){
  $sid = ($_REQUEST['sid']=='0') ? '' : " and shopid=$_REQUEST[sid] ";
}

if($_REQUEST['jie']!=''){
  $jie = ($_REQUEST['jie']=='0') ? " and blance_state=0" : " and blance_state = $_REQUEST[jie] ";
}

// 综合查询信息
$query=mysql_query("select s.shopid,s.name,s.leimu,s.tel,s.rates,g.ordersid,g.numbers,g.totalprice,g.fu_kuan_datetime,g.balance_time,g.blance_price,g.coupon_price,g.blance_state,g.return_volume_price,g.distribution_fee,g.shou_huo_datetime,g.pay_type from goodsorders as g left join shop as s on g.shopid=s.shopid where g.state>0 and g.state<>4 and g.state<>6 ".$cid.$sid.$between.$jie.' order by g.fu_kuan_datetime desc'." limit $startCount,$perNumber");
while ($row = mysql_fetch_assoc($query)) {
  $orders[] = $row;
}


$i=0;
$ordersAll = $orders;
  foreach($orders as $k=>$v){
    $goodsid=mysql_fetch_assoc( mysql_query("select * from car where ordersid=$v[ordersid]") )['goodsid'];
    $cateid=mysql_fetch_assoc( mysql_query('select xilie from goods where goodsid='.$goodsid) )['xilie'];

    $quanrate=mysql_fetch_assoc( mysql_query('select rate from categroy where cateid='.$cateid) )['rate'];

    $ordersAll[$k]['quanrate'] = $quanrate;//返券率
    $ordersAll[$k]['quan'] = ( ($v['totalprice'] * $quanrate / 100)<=0.01 )? 0.01 : round($v['totalprice'] * $quanrate / 100,2);//返券金额

    $ordersAll[$k]['yongrate'] = $v['rates'];//返佣率
    $ordersAll[$k]['yong'] = ( ($v['rates'] * $v['totalprice'] / 100)<=0.01)? 0.01 : round($v['rates'] * $v['totalprice'] /100,2);//返佣金额

    //$ordersAll[$k]['orderRest'] = $v['totalprice'] - ( $ordersAll[$k]['quan']+$ordersAll[$k]['yong'] );
    $ordersAll[$k]['orderRest'] = $v['blance_price'];//结算金额
    $ordersAll[$k]['balance_datetime']=$v['balance_time'];
    $ordersAll[$k]['blance_state']=$v['blance_state'];
    $ordersAll[$k]['volume_price']=$v['return_volume_price'];
    $ordersAll[$k]['kuaidifee']=$v['distribution_fee'];


/*
    if($v['shou_huo_datetime'] && $v['fu_kuan_datetime']){
      $ordersAll[$k]['balance_datetime'] = date('Y-m-d H:i:s', ( strtotime('+7 day',strtotime($v['shou_huo_datetime'])) ) );
    }else if($v['fu_kuan_datetime']){
      $ordersAll[$k]['balance_datetime'] = date('Y-m-d H:i:s', ( strtotime('+23 day',strtotime($v['fu_kuan_datetime'])) ) );
    }
*/
//商品、优惠券、返券、返佣金额合计
    if($i==0){
      $totalNum = $v['totalprice']; $totalCoupon = $v['coupon_price']; $totalQuan = $ordersAll[$k]['quan']; $totalYong = $ordersAll[$k]['yong']; $totalBlance = $v['blance_price'];
    }else{
      $totalNum += $v['totalprice']; $totalCoupon += $v['coupon_price']; $totalQuan += $ordersAll[$k]['quan'];  $totalYong += $ordersAll[$k]['yong']; $totalBlance += $v['blance_price'];
    }
    $i++;

  }


// 查询全部分类
$query = mysql_query("select cateid,name from categroy");
while ($row = mysql_fetch_assoc($query)) {
  $categroys[] = $row;
}
// 查询全部分类 end

// 查询全部商家
$query = mysql_query("select shopid,name from shop");
while ($row = mysql_fetch_assoc($query)) {
  $shops[] = $row;
}
// 查询全部商家 end
  ?>
  <script type="text/javascript" src="js/jquery.min.js"></script>
  <link href="css/styles.css" rel="stylesheet" type="text/css" />
  <link href="css/style2.css" rel="stylesheet" type="text/css" />
  <script type="text/JavaScript">
    <!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>

<body>
<!-- 13924075438 -->
  <!--header-->
  <?php include("common/header.php");?>
  <!--header end-->


  <!-- staqrt subnav -->
  <div id="sub_nav">

  <div class="container aligns" >

    <form style="width:100%" action="" method="post">

      <select name='jie' class="select jiesuan">
        <option value="">全部分类</option>
        <option <?php if($_REQUEST[jie] == '0'){ ?> selected <?php } ?> value='0'>未结算</option>
        <option <?php if($_REQUEST[jie] == '1'){ ?> selected <?php } ?> value='1'>已结算</option>
      </select>

      <span>开始时间</span>
      <input name="date" type="text" value="<?php echo $date; ?>" style="cursor:pointer;" onClick="WdatePicker()"/>
      &nbsp;&nbsp;&nbsp;
      <span>结束时间</span>
      <input name="dateL" type="text" value="<?php echo $dateL; ?>" style="cursor:pointer;" onClick="WdatePicker()"/>

      <label>分类</label> 
      <select name='categroys' class="select categroys">
        <option value="0">全部分类</option>
        <?php foreach ($categroys as $v) { ?>
        <option <?php if($_REQUEST[cid] == $v[cateid]){ ?> selected <?php } ?> value="<?php echo $v[cateid]; ?>"><?php echo $v[name]; ?></option>
        <?php } ?>
      </select>

      <label>商家</label>

      <select name='shops' class="select shops">
        <option value="0">全部商家</option>
        <?php foreach ($shops as $v) { ?>
        <option <?php  if($_REQUEST['sid'] == $v[shopid]){ ?> selected="selected" <?php } ?> value="<?php echo $v[shopid]; ?>" ><?php echo $v[name]; ?></option>
        <?php } ?>
      </select>

      <input type="submit" value="提交" id='jiecha' class="submit">
    </form>
  </div>

  <div class="container_12" style="background: #fff; border:0px;">

  </div>
    <form id="form" action="?sid=<?php  echo $_REQUEST[shopid]; ?>" method="post">
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr class='even'>
            <th width="8%" scope="col">订单号/商铺名称</th>
            <th width="5%" scope="col">商铺代码</th>
            <th width="8%" scope="col">订单总额</th>
            <th width="6%" scope="col">返券率</th>
            <th width="6%" scope="col">返券金额</th>
            <th width="6%" scope="col">优惠券</th>
            <th width="6%" scope="col">返佣率</th>
            <th width="8%" scope="col">返佣金额</th>
            <th width="8%" scope="col">使用返佣金额</th>
            <th width="6%" scope="col">快递/运费</th>
            <th width="12%" scope="col">付款时间/结算时间</th>
            <th width="6%" scope="col">结算金额</th>
            <th width="6%" scope="col">结算状态</th>
            <th width="8%" scope="col">操作</th>
        </tr>
          <?php foreach($ordersAll as $vs){ ?>
          <tr class='even'>
            <td width="8%" scope="col"> <a style="color:red" href="file2.php?id=<?php echo $vs['ordersid'];?>"> <?php echo $vs['numbers'] ?> </a><br/>
            <?php echo $vs['name'] ?></td>
            <td width="8%" scope="col"><?php echo $vs['tel'] ?></td>
            <td width="5%" scope="col">￥ <?php echo $vs['totalprice'] ?></td>
            <td width="6%" scope="col"><?php echo $vs['quanrate'] ?>% </td>
            <td width="6%" scope="col">￥ <?php echo $vs['quan'] ?></td>
            <td width="6%" scope="col">￥ <?php echo $vs['coupon_price'] ?></td>
            <td width="6%" scope="col"><?php echo $vs['yongrate'] ?>% </td>
            <td width="8%" scope="col">￥ <?php echo $vs['yong'] ?></td>
            <td width="8%" scope="col">￥ <?php echo $vs['volume_price'] ?></td>
            <td width="6%" scope="col">￥ <?php echo $vs['kuaidifee'] ?></td>
            <td width="12%" scope="col"><?php echo $vs['fu_kuan_datetime'] ?> <br/>
            <?php echo $vs['balance_datetime'] ?></td>
            <td width="6%" scope="col">￥ <?php echo $vs['orderRest'] ?></td>
 
            <td width="6%" scope="col">
            <?php 
              if($vs['blance_state']=='1'){
                echo '已结算';
              }else{
                echo '未结算';
              }
           ?>
            </td>
            <td width="8%" scope="col" ><a href="wallet.php?t=shop&sid=<?php echo $vs['shopid'];?>">查看详情</a></td>
          </tr>
          <?php } ?>
</table>
</form>
<!-- END TABULAR DATA EXAMPLE -->

<!-- update goodsorders set `balance_time`=curtime() where ordersid=6 -->

<div class="grid_12">

<?php

$totalNumber=count($orders);
$totalPage=ceil($totalNumber/$perNumber); //计算出总页数


?>


  <div class="clearfix">
<!-- 
<input  type="button" value="删除选中"  class="submit del" />
<input  type="button" value="一键审核通过"  class="passall submit" /> 
-->
  </div>

  <ul id="pagination">



    <?php  

    if ($page > 1) { //上一页 ?>
    <li><a     href="?page=1&keywords=<?php echo $_REQUEST[keywords]; ?>">首页</a></li>
    <li><a     href="?page=<?php echo ($page-1); ?>&keywords=<?php echo $_REQUEST[keywords]; ?>">上一页</a></li>
    <?php }

    ?>

    <li class="active"><?php echo $page;?></li>

    <?php



    if ($_GET[page]!=$totalPage) { //下一页 ?>
    <li><a href="?page=<?php echo ($page+1); ?>&keywords=<?php echo $_REQUEST[keywords]; ?>">下一页</a></li>
    <?php }

    if ($totalPage>1) { //下一页 ?>
    <li><a href="?page=<?php echo $totalPage; ?>&keywords=<?php echo $_REQUEST[keywords]; ?>">尾页</a></li>

    <?php }?>


  </ul>

</div>

<div class="container">
   <p class='right'>
     <span>商品金额合计：</span><span> <?php echo $totalNum ?> </span>&nbsp;&nbsp;&nbsp;&nbsp;
     <span>优惠券金额合计：</span><span><?php echo $totalCoupon ?></span>&nbsp;&nbsp;&nbsp;&nbsp;
     <span>返券金额合计：</span><span><?php echo $totalQuan ?></span>&nbsp;&nbsp;&nbsp;&nbsp;
     <span>返佣金额合计：</span><span><?php echo $totalYong ?></span>&nbsp;&nbsp;&nbsp;&nbsp;
     <span>结算金额合计：</span><span><?php echo $totalBlance ?></span>&nbsp;&nbsp;&nbsp;&nbsp;
   </p> 
</div>

</div>
<input type="hidden" id="shopid" value="<?php echo $_REQUEST[shopid]; ?>">
<!-- end content wrap -->


</body>
<script type="text/javascript">

  
  // 查询
/*  
  $('.categroys').change(function(){
    var shopid = $('.shops').val();
    var categroyid = $(this).val();
    window.location.href="watermanage.php?cid="+categroyid+"&sid="+shopid;
  });
  // 查询 end
  
  // 查询
  $('.shops').change(function(){
    var categroyid = $('.categroys').val();
    var shopid = $(this).val();
    window.location.href="watermanage.php?cid="+categroyid+"&sid="+shopid;
  });
*/
  $('th,td').attr({align:"center"});
  $('.jiecha').on('click',function(){
    var categroyid = $('.categroys').val();
    var shopid = $('.shops').val();
    var jiesuan = $('.jiesuan').val();
    window.location.href="watermanage.php?cid="+categroyid+"&sid="+shopid+'&jie='+jiesuan;
  });
  // 查询 end

</script>
</html>
